package com.un.ebs.core.metadata;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.un.ebs.core.enums.FuncTypeEnum;
import lombok.Data;
import org.springframework.web.bind.annotation.RequestMethod;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Controller 中所有 @RequestMapping 的 method 数据结构
 */
@Data
public class FunctionInfo implements Serializable {

    /**
     * 指 method.name
     */
    @JsonIgnore
    public String name;
    /**
     * 指 @ApiOperation 中的描述
     */
    public String description;
    /**
     * 指 @RequestMapping 的 method 类型，如 get，post 等
     */
    public List<RequestMethod> method;

    /**
     * 请求地址
     */
    private String url;

    /**
     * 指 method 中的输入参数集合
     */
    private List<RequestArg> request;
    /**
     * 指method 输出参数
     */
    private List<MetadataField> response;
    /**
     * 是否动态查询
     */
    private FuncTypeEnum funcType;

    /**
     * 动态查询方案
     */
    //private List<Query> dynamicQuery;
    public FunctionInfo() {

    }

    public FunctionInfo(String name, String url, String description, RequestMethod method, List<RequestArg> request,
                        List<MetadataField> response) {
        this.name = name;
        this.url = url;
        this.description = description;
        this.request = request;
        this.response = response;

        List<RequestMethod> methods = new ArrayList<>();
        methods.add(method);
        this.method=methods;
    }


    @Override
    public String toString() {
        return "FunctionInfo{" +
                "name='" + name + '\'' +
                ", description='" + description + '\'' +
                ", method=" + method +
                ", request=" + request +
                ", response=" + response +
                '}';
    }
}


